<?php

/**
 * 消息主页
 */

namespace app\api\controller;


use app\api\model\MessageUserHouse;
use app\api\model\MessageUserSystem;
use app\common\controller\ApiController;
use think\Exception;
use app\api\model\Message as MessageModel;
use app\api\model\Banner as BannerModel;

class Message extends ApiController {

    protected $isArrayResult = ['getallhousemessage'];

    /**
     * 消息主页
     * @return false|string
     */
    public function getMessage() {
        try {
            $params = $this->checkParams('');
            if ($params === false) {
                return $this->resErr();
            }
            $data = MessageModel::get_message($params);
            return $this->resData('success', $data);
        } catch (Exception $e) {
            return $this->resErr($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 所有系统消息
     * @return false|string
     */
    public function getAllsystemMessage() {
        try {
            $params = $this->checkParams('');
            if ($params === false) {
                return $this->resErr();
            }
            $data = MessageUserSystem::getAllsystemMessage($params);
            $banner = BannerModel::systembanner();
            return $this->resData('success', ['banner' => $banner, 'list' => $data]);
        } catch (Exception $e) {
            return $this->resErr($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 智能选房消息
     * @return false|string
     */
    public function getAllHouseMessage() {
        try {
            $params = $this->checkParams('');
            if ($params === false) {
                return $this->resErr();
            }
            $data = MessageUserHouse::getAllHouseMessage($params);
            return $this->resData('success', $data);
        } catch (Exception $e) {
            return $this->resErr($e->getMessage(), $e->getCode());
        }
    }
}
